package com.market.controller;

import com.market.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/welcome")
public class WelcomeController {
    @Autowired
    private BillService billService;

    /**
     * 获取账单统计数据（今日、昨日、本周、本月账单数）
     */
    @GetMapping("/statBillCount")
    public Map<String, Object> statBillCount() {
        Map<String, Object> result = new HashMap<>();
        try {
            Map<String, Object> statData = billService.getStatBillCount();
            result.put("flag", true);
            result.put("data", statData);
        } catch (Exception e) {
            result.put("flag", false);
            result.put("message", "获取账单统计数据失败: " + e.getMessage());
        }
        return result;
    }
    
    /**
     * 获取最近7天账单数量趋势
     */
    @GetMapping("/last7DaysBillCount")
    public Map<String, Object> getLast7DaysBillCount() {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Map<String, Object>> countData = billService.getLast7DaysBillCount();
            result.put("flag", true);
            result.put("data", countData);
        } catch (Exception e) {
            result.put("flag", false);
            result.put("message", "获取最近7天账单数量趋势失败: " + e.getMessage());
        }
        return result;
    }
    
    /**
     * 获取最近7天账单金额趋势
     */
    @GetMapping("/last7DaysBillAmount")
    public Map<String, Object> getLast7DaysBillAmount() {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Map<String, Object>> amountData = billService.getLast7DaysBillAmount();
            result.put("flag", true);
            result.put("data", amountData);
        } catch (Exception e) {
            result.put("flag", false);
            result.put("message", "获取最近7天账单金额趋势失败: " + e.getMessage());
        }
        return result;
    }
} 